window.zsmm = {};
Zepto(function ($) {

    FastClick.attach(document.body);

    document.documentElement.ontouchstart = function (e) {
        if ($(e.target).attr('data-onhover') && $(e.target).data('onhover')) {
            $(e.target).addClass($(e.target).data('onhover'));
        }
    }
    document.documentElement.ontouchend = function () {
        $('[data-onhover]').each(function () {
            $(this).removeClass($(this).data('onhover'));
        });
    }
    $("body").delegate('[data-href]', 'click', function (e) {//页面跳转
        window.location.href = $(this).data('href');
        return false;
    }).delegate('[data-spopup]', 'click', function () {//显示弹出框
        if ($($(this).data('spopup'))) {
            $($(this).data('spopup')).show();
            $($(this).data('spopup')).siblings().addClass("disableClick");
            $("body").css("overflow-y", "hidden");
        };
    }).delegate('[data-cpopup]', 'click', function () {//隐藏弹出框
        if ($($(this).data('cpopup'))) {
            $($(this).data('cpopup')).hide();
            $($(this).data('cpopup')).siblings().removeClass("disableClick");
            $("body").css("overflow-y", "auto");
        };
    });
});

zsmm.Toast = {
    isopen: true,
    ins: null,
    intval: 0,
    New: function (msg, remain) {
        var that = this;
        if (this.isopen && this.ins) {
            this.clear();
        }

        this.instance(msg);
        remain || (remain = 2);
        this.intval = setTimeout(function () {
            that.ins.css('opacity', 0);
        }, remain * 1000);
    },
    instance: function (msg) {
        this.ins = $('<div id="global-toast"></div>');
        this.ins.appendTo('body');
        this.ins.html(msg);
        this.ins.css('margin-left', (-this.ins.width() / 2) + 'px');
        this.ins.show();
        var that = this;
        this.ins[0].addEventListener("transitionend", function () {
            that.clear();
        });
        this.ins[0].addEventListener("webkitTransitionEnd", function () {
            that.clear();
        });
    },
    clear: function () {
        this.ins.remove();
        this.ins = null;
        clearTimeout(this.intval);
    }
};

